#include "HowToPlayMenuState.h"
#include "OptionsMenuState.h"
#include "MainMenuState.h"
#include "CSGD_DirectInput.h"
#include "CSGD_TextureManager.h"
#include "CSGD_XAudio2.h"
#include "Game.h"
#include "BitmapFont.h"
#include "../resource.h"

/////////////////////////////////////////////////////////////////////////////
// Function		: CHowToPlayMenuState
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
CHowToPlayMenuState::CHowToPlayMenuState(void)
{
	m_nBackgroundImg = -1;
}
/////////////////////////////////////////////////////////////////////////////
// Function		: ~CHowToPlayMenuState
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
CHowToPlayMenuState::~CHowToPlayMenuState(void)
{
}
/////////////////////////////////////////////////////////////////////////////
// Function		: GetInstance
// Return		: CHowToPlayMenuState*
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
CHowToPlayMenuState* CHowToPlayMenuState::GetInstance( void )
{
	static CHowToPlayMenuState s_Instance;

	return &s_Instance;
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Enter
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CHowToPlayMenuState::Enter( void )
{
	m_nBackgroundImg = CSGD_TextureManager::GetInstance()->LoadTexture(_T("resource/Images/MenuBackground.png"));

	if(COptionsMenuState::GetInstance()->ReturnEng())
	{
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Control1, Control1, 200);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Control2, Control2, 20);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Control3, Control3, 20);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Control4, Control4, 50);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Control5, Control5, 20);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Control6, Control6, 20);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Control7, Control7, 40);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_Control8, Control8, 60);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Eng_EscToMain, EscToMain, 50);
	}
	else
	{
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Control1, Control1, 200);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Control2, Control2, 20);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Control3, Control3, 20);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Control4, Control4, 50);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Control5, Control5, 20);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Control6, Control6, 20);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Control7, Control7, 40);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_Control8, Control8, 60);
		LoadString(CGame::GetInstance()->ReturnInsance(), ID_Swa_EscToMain, EscToMain, 50);
	}

	TrueEscTMain = "";

	for (int character = 0; character < 50; character++)
	{
		if(EscToMain[character] != NULL)
			TrueEscTMain += (char)EscToMain[character];
		else
			break;
	}

}
/////////////////////////////////////////////////////////////////////////////
// Function		: Exit
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CHowToPlayMenuState::Exit ( void )
{
	CSGD_TextureManager::GetInstance()->UnloadTexture(m_nBackgroundImg);
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Input
// Return		: bool
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
bool CHowToPlayMenuState::Input( void )
{
	CSGD_DirectInput* m_pDI = CSGD_DirectInput::GetInstance();

	if( m_pDI->KeyPressed( DIK_ESCAPE ) == true || m_pDI->JoystickButtonPressed(1,0) )
	{
		CSGD_XAudio2::GetInstance()->SFXPlaySound(CGame::GetInstance()->GetConfirmID());
		CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
	}

	return true;	
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Update
// Paramater	: fElapsedTime - The ammount of time passed since last update
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CHowToPlayMenuState::Update( float fElapsedTime )
{
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Render
// Notes		: 
/////////////////////////////////////////////////////////////////////////////
void CHowToPlayMenuState::Render( void )
{
	CSGD_TextureManager::GetInstance()->Draw(m_nBackgroundImg, 0,0, 1.0f,1.0f);

	CBitmapFont* font = CGame::GetInstance()->GetFont();

	font->Draw( EscToMain, CGame::GetInstance()->GetScreenMidPoint(TrueEscTMain, 1.0f), 568,1.0f, 
		D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw( Control1, 100, 50, 1.0f, 
		D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw( Control2, 100, 200, 1.0f, 
		D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw( Control3, 100, 250, 1.0f, 
		D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw(Control4, 100, 300, 1.0f, 
		D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw( Control5, 100, 350, 1.0f, 
		D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw(Control6, 100, 400, 1.0f, 
		D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw(Control7, 100, 450, 1.0f, 
		D3DCOLOR_ARGB( 255, 255, 0, 0 ) );

	font->Draw(Control8, 100, 500, 0.75f, 
		D3DCOLOR_ARGB( 255, 255, 0, 0 ) );
}